package com.kakaxi.mybilibili.view;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.util.AttributeSet;

import fm.jiecao.jcvideoplayer_lib.JCUtils;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * 自定义节操视频播放器
 * Created by kakaxi on 16/11/22.
 */

public class MyJCVideoPlayer extends JCVideoPlayerStandard {

    private OnVisibilityChangedListener mListener;

    public MyJCVideoPlayer(Context context) {
        super(context);
    }

    public MyJCVideoPlayer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void startWindowFullscreen() {
        super.startWindowFullscreen();
        // 强制满屏横屏
        JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(ActivityInfo
                .SCREEN_ORIENTATION_LANDSCAPE);
    }


    @Override
    public void onClickUiToggle() {
        super.onClickUiToggle();
        if (mListener != null) {
            mListener.onVisibilityChanged(currentScreen, currentState, bottomContainer
                    .getVisibility());
        }
    }


    public void setOnVisibilityChangedListener(OnVisibilityChangedListener
                                                       onVisibilityChangedListener) {
        mListener = onVisibilityChangedListener;
    }

    public OnVisibilityChangedListener getOnVisibilityChangedListener() {
        return mListener;
    }

    /**
     * 显示变化监听器
     */
    public interface OnVisibilityChangedListener {

        /**
         * 显示变化监听事件
         *
         * @param currentScreenState         当前播放器屏幕状态
         * @param currentPlayerState         当前播放器播放状态
         * @param currentViewVisibilityState 当前视图的显示状态
         */
        void onVisibilityChanged(int currentScreenState, int currentPlayerState, int
                currentViewVisibilityState);

    }

}
